//  肥胖度
import MeasureItem from './MeasureItem'
import Calc from './Calc'

const UI = require('./UI');
const STAND_LEVEL = 1;
const BAR = [UI.color.report_stand, UI.color.report_higher, UI.color.report_orange_highest,UI.color.report_highest,UI.color.report_claret_sufficient];
export default class ObesityDegreeReport {


  static getStand(measure) {
    let weightControl;
    if (measure.gender == 0) {
      weightControl = ((measure.height * 1.37) - 110) * 0.45;
    } else {
      weightControl = (measure.height - 80) * 0.7;
    }

    return weightControl;
  }

  static getIdeaWeight(height) {
    return (height - 105);
  }
  /**
   * 肥胖度超过15%为超重，肥胖度超过32%~52%为轻度肥胖，超过52%~74%为中度肥胖，超过74%以上为重度肥胖
   */
  static isEnable(measure) {
    return true
  }
  static build(measure) {
    const item = new MeasureItem();
    let standWeight = ObesityDegreeReport.getStand(measure);
    const boundaries = [15, 32, 52, 74];
    let level = 0;
    let value = (( measure.weight- standWeight) * 100 / standWeight).toFixed(2);
    const isStand = level == STAND_LEVEL;
    let values = [100 * 0.15, 100 * 0.32, 100 * 0.52, 100 * 0.74];
    const desc = "判断是否肥胖的指标";

    for (let i = 0; i < values.length; i++) {
      values[i] = (values[i]).toFixed(2);
    }

    if (value < 0) {
      value = 0;
      level = Calc.calcLevel(value, boundaries, 0)
    } else {
      level = Calc.calcLevel(value, boundaries, 1)
    }
    item.name = "肥胖度";
    item.boundaries = boundaries;
    item.value = value;
    item.levelNames = ["标准", "超重", "轻度肥胖", "中度肥胖", "严重肥胖"];
    item.isStand = isStand;
    item.unit = "%";
    item.desc = desc;
    item.level = level;
    item.bar = BAR;

    item.min = 5;
    item.max = 75;
    item.levelName = item.levelNames[item.level]
    item.levelColor = item.bar[item.level]

    if (!isStand) {
      let offset = 0;
      if (level < STAND_LEVEL) {
        offset = value - boundaries[STAND_LEVEL - 1]
      } else {
        offset = value - boundaries[STAND_LEVEL]
      }
      item.offset = offset
    }

    return item
  }

}



// WEBPACK FOOTER //
// ./src/report/ObesityDegree.js
